Prev Next |
Most developers begin using the Sitecore API when writing Layout or Sublayout code-behind or web controls. Regardless of what the developer needs to do, understanding how to complete the task starts with understanding the context in which custom code executes. The Sitecore runtime process runs as a part of the .NET framework running on a web server, usually Microsoft’s Internet Information Server (IIS). When IIS serves a Sitecore web site, it passes HTTP requests to the Sitecore process, which sends the requests to the Sitecore HTTP Request Pipeline.
The HTTP Request Pipeline is a predefined series of method calls which build up information about the current environment and the current request, followed by a call to another pipeline which builds a response to the request, which, for most pages on a normal web site, is the Render Layout Pipeline. Sitecore Pipelines are fully customizable.
The HTTP Request Pipeline includes many steps, and many of these are devoted to interrogating the HTTP request to gather information about the current request and the web.config file to garnish information about the current environment. This information is passed between steps and ultimately to custom code-behind code or web controls in the Sitecore.Context object.
Developers therefore often start custom code with calls to the Sitecore.Context object to obtain a pointer to the requested Sitecore Item, the current User, the Database associated with the current web site, information about attributes included in the Query String, and much more.
For example, the following code retrieves a pointer to the requested Item and requests the name of the current user.
Sitecore.Data.Item requested_item = Sitecore.Context.Item;
string = Sitecore.Context.GetUserName( );
The table below provides a list of the most commonly used Sitecore.Context members.
Database |
Gets the current database as a Sitecore.Data.Database object |
Device |
Gets the current security domain as a Sitecore.SecurityModel.Domain object |
Item |
Gets the requested Item as a Sitecore.Data.Items.Item object. Can also be used to set the current Item in the context from a custom Pipeline step. |
Language |
Gets the current language as a Sitecore.Globalization.Language object. |
Site |
Gets the current Site as a Sitecore.Sites.SiteContext object. |
User |
Gets the current User as a Sitecore.SecurityModel.UserItem object. |
GetDeviceName |
Gets the name of the current device. |
GetDomainName |
Gets the name of the current security domain. |
GetUserName |
Gets the name of the current user. |
Prev Next